package com.hanhanxiaochong.zhongxiangchuanmei.presenter.my;

import com.hanhanxiaochong.zhongxiangchuanmei.bean.ProvinceBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.HttpPostService;
import com.hanhanxiaochong.zhongxiangchuanmei.presenter.base.BasePresenter;
import com.hanhanxiaochong.zhongxiangchuanmei.view.iview.IAddBankCardView;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseApi;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseObserver;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.ResponseBase;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;

import java.util.List;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Author : 贾桐
 * E-mail : 653773284@qq.com
 * Time   : 2018/6/11.
 * Desc   :
 */

public class AddBankCardPresenter extends BasePresenter<IAddBankCardView> {

    public AddBankCardPresenter(IAddBankCardView iView) {
        super(iView);
    }

    public void sendMsg(String phone, String type) {
        addSubscription(RetrofitSource.createApi(HttpPostService.class).sendTemplateSMS(phone, type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<String>>(iView) {
                    @Override
                    public void onSuccess(ResponseBase<String> response) {

                    }

                }));
    }

    public void getProvince(String p_id){
        addSubscription(RetrofitSource.createApi(HttpPostService.class).getProvinceOrCity(p_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<List<ProvinceBean>>>(iView) {
                    @Override
                    public void onSuccess(ResponseBase<List<ProvinceBean>> response) {
                        iView.getProvince(response.getData());
                    }
                }));
    }

    public void getCity(String p_id){
        addSubscription(RetrofitSource.createApi(HttpPostService.class).getProvinceOrCity(p_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<List<ProvinceBean>>>(iView) {
                    @Override
                    public void onSuccess(ResponseBase<List<ProvinceBean>> response) {
                        iView.getCity(response.getData());
                    }
                }));
    }

    public void getBank(){
        addSubscription(RetrofitSource.createApi(HttpPostService.class).getBank()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<List<String>>>(iView) {
                    @Override
                    public void onSuccess(ResponseBase<List<String>> response) {
                        iView.getBank(response.getData());
                    }
                }));
    }

    public void addCard(String ca_name, String ca_phone, String ca_number, String city1, String city2,
                        String token, String code, String ca_ress, String ca_wxbanklist){
        addSubscription(RetrofitSource.createApi(HttpPostService.class)
                .AddCard(ca_name, ca_phone, ca_number, city1, city2, token, code, ca_ress, ca_wxbanklist)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<String>>(iView) {
                    @Override
                    public void onSuccess(ResponseBase<String> response) {
                        iView.addCard(response.getData());
                    }
                }));
    }



    @Override
    public void startPost(RxAppCompatActivity rxAppCompatActivity, BaseApi baseApi) {

    }

    @Override
    public void startPost(RxAppCompatActivity rxAppCompatActivity, BaseApi baseApi, int state) {

    }
}
